import java.util.Arrays;

/**
 * @author wangj881
 * @date 2025-01-03 16:35
 */
public class L189_3 {

    public static void main(String[] args) {
        int[] nums = {1, 2};
        int k = 3;
        new Solution().rotate(nums, k);
    }

    static class Solution {
        public void rotate(int[] nums, int k) {
            if (nums.length < 2) {
                return;
            }
            if (nums.length < k) {
                k = k % nums.length;
            }


            swap(nums, 0, nums.length - 1);
            swap(nums, 0, k - 1);
            swap(nums, k, nums.length - 1);
            System.out.println(Arrays.toString(nums));


        }

        private void swap(int[] nums, int left, int right) {
            while (left < right) {
                int tmp = nums[left];
                nums[left] = nums[right];
                nums[right] = tmp;
                left++;
                right--;
            }

        }
    }
}
